<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="材料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="输入材料名称模糊查询" v-model="queryParam.name"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="材料类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="输入材料类型模糊查询" v-model="queryParam.type"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="border-top: 5px">
          <a-button  @click="handleAdd" type="primary" icon="plus">新增</a-button>
        </div>
        <div>
          <a-table
            ref="table"
            bordered
            size="middle"
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            @change="handleTableChange">
            <span slot="action" slot-scope="text, record">
               <a-divider v-if="btnEnableList.indexOf(1)>-1" type="vertical"/>
              <a v-if="btnEnableList.indexOf(1)>-1" @click="handleEdit(record)">编辑</a>
              <a-divider v-if="btnEnableList.indexOf(4)>-1" type="vertical"/>
              <a-popconfirm v-if="btnEnableList.indexOf(4)>-1" title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
           
            </span>
            <!-- 状态渲染模板 -->
            <template slot="customRenderFlag" slot-scope="status">
              <a-tag v-if="status===0" color="green">启用</a-tag>
              <a-tag v-if="status===2" color="orange">禁用</a-tag>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
        <storage-modal ref="modalForm" @ok="modalFormOk"></storage-modal>
      </a-card>
    </a-col>
  </a-row>
</template>

<script>
  import StorageModal from './modules/StorageModal'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import JInput from '@/components/jeecg/JInput'
  export default {
    name: "StorageList",
    mixins: [JeecgListMixin],
    components: {
      StorageModal,
      JInput
    },
    data() {
      return {
        labelCol: {
          span: 5
        },
        wrapperCol: {
          span: 18,
          offset: 1
        },
        queryParam: {},
        depotFlag: '0',
        customerFlag: '0',
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:40,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
           { title: '仓库名称', dataIndex: 'warehouseName', width: 100, align: "center"},
          { title: '材料名称', dataIndex: 'name', width: 100, align: "center"},
          { title: '材料类型', dataIndex: 'type', width: 100, align: "center"},
          { title: '材料数量', dataIndex: 'num', width: 100, align: "center"},
          { title: '材料单位', dataIndex: 'unit', width: 100, align: "center"},
          { title: '材料描述', dataIndex: 'description', width: 115, align: "center"},
          { title: '创建人', dataIndex: 'createUserStr', width: 70, align: "center"},
          { title: '创建时间', dataIndex: 'createTimeStr', width: 140, align: "center"},
          {
            title: '操作',
            dataIndex: 'action',
            scopedSlots: {customRender: 'action'},
            align: "center",
            width: 260
          }
        ],
        url: {
          list: "/storage/list",
          delete: "/storage/delete",
          deleteBatch: "/storage/deleteBatch",
          batchSetStatusUrl: "/storage/batchSetStatus"
        },
      }
    },
   
    methods: {
      searchQuery() {
        this.loadData(1);
      },
      searchReset() {
        this.queryParam = {}
        this.loadData(1);
      },
      handleEdit: function (record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = "编辑";
        this.$refs.modalForm.disableSubmit = false;
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>